<template>
  <div class="container">
    <van-search
      v-model="searchform.iOrgname"
      show-action
      placeholder="请输入机构名称"
      @search="onSearch"
    >
      <template #action>
        <div @click="onSearch">搜索</div>
      </template>
    </van-search>
    <div class="list-container">
      <div class="section">
        <p v-if="listData.length===0" class="yyp">
          <van-empty description="暂无数据~"/>
        </p>
        <van-swipe-cell v-else>
          <van-checkbox-group v-model="refApp">
            <van-checkbox v-for="(item,index) in listData" :name="item" :key="index">
              <div class="yycard">
                <div class="yycard_p">
                  <p>{{item.strParorgnum}}</p>
                </div>
              </div>
            </van-checkbox>
          </van-checkbox-group>
        </van-swipe-cell>
      </div>
    </div>
    <div class="bottom">
      <van-button v-if="listData.length>0" type="primary" block @click="submitcheck()">添加</van-button>
    </div>
  </div>
</template>

<script>
  import {getOrgList} from '@/api/application'

  export default {
    name: 'SearchOrg',
    data() {
      return {
        listData: [],
        refApp: [],
        loading: false,
        searchform: {
          iOrgname: '',
          iOrgsysnum: localStorage.getItem('iOrgsysnum')
        }
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      //获取机构编号列表
      fetchData() {
        getOrgList(this.searchform).then(res => {
          this.listData = res.orgList
        })
      },
      onSearch() {
        this.fetchData()
      },
      submitcheck() {
        let showarr = []
        this.refApp.forEach((item, index) => {
          showarr.push({
            iOrgsysnum: item.iOrgsysnum,
            strParorgnum: item.strParorgnum
          })
          this.$router.push({path: 'addApplication', query: {Orgparam: showarr}})
        });
      }
    }
  }
</script>

<style lang="scss" scoped>
  .container {
    height: 100%;

    .list-container {
      display: flex;
      flex-direction: column;

      .section {
        flex: 1;
        height: 425px;
        max-height: 425px;
        overflow: auto;
        padding-bottom: 100px;
      }

      .bottom {
        flex: 1;
        display: flex;
        justify-content: center;
        align-content: center;
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        background: #fafafa;

        .van-button {
          width: 90%;
        }
      }
    }
  }

  .yyp {
    text-align: center;
    font-size: 14px;
    color: #8c8a8a;
    line-height: 2;
  }

  .yycard {
    display: flex;
    border-bottom: 1px solid whitesmoke;
    padding: 5px 0;
    margin-left: 20px;
    width: 300px;
    height: 35px;
    align-items: center;
  }

  .yyimg {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    background-color: #F5F7FA;
  }

  .yycard_p {
    font-size: 14px;
    line-height: 20px;
    vertical-align: middle;
    padding-left: 10px;
    color: #6b6b6b;
  }

  .yycard_title {
    font-size: 14px;
    color: #000;
  }

  .van-button--primary {
    background-color: #0c1b35;
    border-color: #0c1b35;
    border-radius: 4px;
    width: 90%;
    margin: 20px;
  }

  .van-button--danger {
    height: 100%;
  }

  .delete-button2 {
    background-color: #6b6b6b;
    border: 1px solid #6b6b6b;
  }

  /deep/ .van-search__content {
    border-radius: 20px;
    background-color: #e7e9ec;
  }

  /deep/ .van-checkbox__icon {
    position: relative;
    left: 25px;
  }

  .ellipsisp {
    width: 300px;
  }
</style>
